home *** CD-ROM | disk | FTP | other *** search
- #include <stdarg.h>
- #include "shape.h"
-
-
- /* Shape */
-
- vFt_def(Shape,Shape) = {
- vF_value(SH,SH,show),
- vF_value(SH,SH,destruct)
- };
-
- /* ARGSUSED */
- #pragma argsused
- vf_def(void,SH,SH,show,(Shape * thiS, int xxpose,
- int yxpose, unsigned scale))
- {}
-
- vf_def(void,SH,SH,destruct,(Shape * thiS,
- unsigned nobj, int malloced))
- {
- struct_destruct(SH,thiS,nobj,malloced);
- }
-
-
- struct_initVFTs_def(SH,(Shape * thiS,
- void * descendanT_0, vFT_0_decl(Shape)))
- {
- poly_assign(thiS,descendanT_0);
- vFT_assign(Shape,Shape,
- thiS,vFT_0_name(Shape));
- }
-
- struct_init_def(Shape,SH,_,
- (Shape * thiS_0, unsigned nobj,
- unsigned x, unsigned y))
- {
- unsigned i;
-
- if (!nobj)
- return (Shape *)0;
- if (!thiS_0) if ((thiS_0 = (Shape *)
- SH_malloc(nobj))
- == (Shape *)0)
- return (Shape *)0;
- for (i = 0; i < nobj; i++) {
- struct_initVFTs(SH,(&thiS_0[i],(void *)0,
- vFT0(Shape)));
- thiS_0[i].x = x;
- thiS_0[i].y = y;
-
- } /* for */
- return thiS_0;
- }
-
- struct_destruct_def(Shape,SH)
- {
- unsigned i;
-
- if (!thiS_0 || !nobj)
- return;
-
- for (i = nobj; i--; /* no reinit */) {
- struct_initVFTs(SH,(&thiS_0[i],
- (void *)0,vFT0(Shape)));
- }
-
- if (malloced)
- SH_free(thiS_0);
- }
-
-
-
- /* Segment */
-
- polyBaseThiS_0_def(SG,Shape,Segment)
-
- vFt_def(Segment,Shape) = {
- vF_value(SG,SH,show),
- vF_value(SG,SH,destruct)
- };
-
- vf_def(void,SG,SH,show,(Shape * thiS, int xxpose,
- int yxpose, unsigned scale))
- {
- unsigned i;
- Segment * SGthiS = SH_SegmentThiS(thiS);
-
- if (SGthiS->shapeCount)
- for (i = 0; i < SGthiS->shapeCount; i++)
- /*lint -e506 */
- if(SGthiS->shapes[i])
- SH_show(SGthiS->shapes[i],
- (int)SG_getx(SGthiS)+xxpose,
- (int)SG_gety(SGthiS)+yxpose,
- scale);
- /*lint +e506 */
- }
-
- vf_def(void,SG,SH,destruct,(Shape * thiS,
- unsigned nobj, int malloced))
- {
- struct_destruct(SG,SH_SegmentThiS(thiS),
- nobj,malloced);
- }
-
- struct_initVFTs_def(SG,(Segment * thiS,
- void * descendanT_0
- , vFT_0_decl(Shape)))
- {
- poly_assign(thiS,descendanT_0);
- struct_initVFTs(SH,
- (SG_ShapeThiS(thiS), (void *) thiS,
- vFT_0_name(Shape)));
- }
-
- struct_init_def(Segment,SG,_,
- (Segment * thiS_0, unsigned nobj,
- unsigned x, unsigned y,
- unsigned shapeCount, ...))
- {
- unsigned i, j, fail;
- int malloced = 0;
- va_list shapes;
- /*
- Since all shapes must be dynamically allocated
- nobj is allowed only to be 1. nobj could be
- greater than 1 if shapes had a virtual clone
- function or better yet a link count. To do so
- would have made the example even more
- complicated.
- */
-
-
- if (!nobj || (nobj > 1) || !shapeCount)
- return (Segment *)0;
- if (!thiS_0) if ((thiS_0 = (Segment *)
- SG_malloc(nobj))
- == (Segment *)0)
- return (Segment *)0;
- else
- malloced = 1;
- for (i = fail = 0; i < nobj; i++) {
- if (!struct_init(SH,_,(SG_ShapeThiS(&thiS_0[i]),
- 1,x,y))) {
- fail = 1;
- break;
- }
- struct_initVFTs(SG,(&thiS_0[i], (void *)0,
- vFT_value(Segment,Shape)));
-
- thiS_0[i].shapes = (Shape **) 0;
- thiS_0[i].shapeCount = 0;
- if ((thiS_0[i].shapes = (Shape **)MALLOC(sizeof(Shape *)
- *shapeCount)) != (Shape **)0) {
- va_start(shapes,shapeCount);
- for (j = 0; j < shapeCount; j++)
- thiS_0[i].shapes[j] = va_arg(shapes,Shape *);
- va_end(shapes);
- thiS_0[i].shapeCount = shapeCount;
- }
- else {
- va_start(shapes,shapeCount);
- for (j = 0; j < shapeCount; j++)
- SH_delete(va_arg(shapes,Shape *),1);
- va_end(shapes);
- struct_destruct(SH,SG_ShapeThiS(&thiS_0[i]),1,0);
- fail = 1;
- break;
- }
-
- } /* for */
-
- if (fail) {
- /*
- All indices >= "i" have already been destructed
- as required. Indices i-1 to 0 are now
- destructed via the destructor since we're
- inside the constructor of the instance level if
- i > 0. Remember that if this is an
- intermediate constructor call that i == 0
- and malloced == 0 always so no further
- processing is required at this level and NULL
- is returned to the calling level constructor.
- */
- if (i)
- struct_destruct(SG,thiS_0,i,malloced);
- else if (malloced)
- SG_free(thiS_0);
- return (Segment *) 0;
- }
-
- return thiS_0;
- }
-
- struct_destruct_def(Segment,SG)
- {
- unsigned i, j;
-
- if (!thiS_0 || !nobj)
- return;
-
- for (i = nobj; i--; /* no reinit */) {
-
- struct_initVFTs(SG,(&thiS_0[i], (void *)0,
- vFT_value(Segment,Shape)));
-
- if (thiS_0[i].shapeCount) {
- for (j = 0; j < thiS_0[i].shapeCount; j++)
- SH_delete(thiS_0[i].shapes[j],1);
- FREE(thiS_0[i].shapes);
- }
-
- struct_destruct(SH,SG_ShapeThiS(&thiS_0[i]),1,0);
-
- }
-
- if (malloced)
- SG_free(thiS_0);
- }
-
-
-
- /* Circle */
-
- polyBaseThiS_0_def(CR,Shape,Circle)
-
- vFt_def(Circle,Shape) = {
- vF_value(CR,SH,show),
- vF_value(CR,SH,destruct)
- };
-
- vf_def(void,CR,SH,show,(Shape * thiS, int xxpose,
- int yxpose, unsigned scale))
- {
- Circle * CRthiS = SH_CircleThiS(thiS);
-
- /*lint -e506 */
- circle((int)CR_getx(CRthiS)+xxpose,
- (int)CR_gety(CRthiS)+yxpose,
- (int)(CRthiS->radius*scale));
- /*lint +e506 */
- }
-
- vf_def(void,CR,SH,destruct,(Shape * thiS,
- unsigned nobj, int malloced))
- {
- struct_destruct(CR,SH_CircleThiS(thiS),
- nobj,malloced);
- }
-
- struct_initVFTs_def(CR,(Circle * thiS,
- void * descendanT_0
- , vFT_0_decl(Shape)))
- {
- poly_assign(thiS,descendanT_0);
- struct_initVFTs(SH,
- (CR_ShapeThiS(thiS), (void *) thiS,
- vFT_0_name(Shape)));
- }
-
- struct_init_def(Circle,CR,_,
- (Circle * thiS_0, unsigned nobj,
- unsigned radius,
- unsigned x, unsigned y))
- {
- unsigned i, fail;
- int malloced = 0;
-
- if (!nobj)
- return (Circle *)0;
- if (!thiS_0) if ((thiS_0 = (Circle *)
- CR_malloc(nobj))
- == (Circle *)0)
- return (Circle *)0;
- else
- malloced = 1;
- for (i = fail = 0; i < nobj; i++) {
- if (!struct_init(SH,_,(CR_ShapeThiS(&thiS_0[i]),
- 1,(x?x:radius),(y?y:radius)))) {
- fail = 1;
- break;
- }
- struct_initVFTs(CR,(&thiS_0[i], (void *)0,
- vFT_value(Circle,Shape)));
-
- thiS_0[i].radius = radius;
-
- } /* for */
-
- if (fail) {
- /*
- All indices >= "i" have already been destructed
- as required. Indices i-1 to 0 are now
- destructed via the destructor since we're
- inside the constructor of the instance level if
- i > 0. Remember that if this is an
- intermediate constructor call that i == 0
- and malloced == 0 always so no further
- processing is required at this level and NULL
- is returned to the calling level constructor.
- */
- if (i)
- struct_destruct(CR,thiS_0,i,malloced);
- else if (malloced)
- CR_free(thiS_0);
- return (Circle *) 0;
- }
-
- return thiS_0;
- }
-
- struct_destruct_def(Circle,CR)
- {
- unsigned i;
-
- if (!thiS_0 || !nobj)
- return;
-
- for (i = nobj; i--; /* no reinit */) {
-
- struct_initVFTs(CR,(&thiS_0[i], (void *)0,
- vFT_value(Circle,Shape)));
-
- struct_destruct(SH,CR_ShapeThiS(&thiS_0[i]),1,0);
-
- }
-
- if (malloced)
- CR_free(thiS_0);
- }
-